import { Request, Response } from 'express';
import operationalService from '../../services/operational.service'
export class Controller {
    // 获取运营位接口
    get(req: Request, res: Response): void {
        let status = Number(req.query.status as string)
        if (!status) {
            status = 0
        }
        operationalService.getOperational(status).then((data)=>{
            res.status(200).json({ msg: 'ok',datas: data })
        }).catch((error)=>{
            res.status(200).json({ msg: 'error', error: error })
        })
    }
    // 新增运营位接口
    add(req: Request, res: Response): void {
        // 解析请求参数
        let name = req.body.name
        let status = req.body.status
        let cover = req.body.cover
        let content = req.body.content
        let uri = req.body.uri
        operationalService.addOperational({ name, status, cover, content, uri }).then(()=>{
            res.status(200).json({ msg: 'ok' })
        }).catch((error)=>{
            res.status(200).json({ msg: 'error', error: error })
        })
    }
    // 更新运营位状态接口
    update(req: Request, res: Response): void {
        let status = req.body.status
        let id = req.body.id
        if (status != 0 && status != 1) {
            status = 0
        }
        if (!id) {
            res.status(200).json({ msg:'error', error:'请指定要更新的运营位id' })
        }
        operationalService.updateOperational(status, id).then(()=>{
            res.status(200).json({ msg:'ok' })
        })
    }
}
export default new Controller();